
import requests
import aiohttp

# 修改为你的HHLServer主机IP和端口
HOST = '127.0.0.1'
PORT = 9780  # 如有不同请修改
url = f'http://{HOST}:{PORT}/app/danmu/send'

def send_huahua_danmu_sync(text: str, userid: str = None, dmid: str = None):
    params = {'text': text}
    if userid:
        params['userid'] = userid
    if dmid:
        params['dmid'] = dmid
    try:
        response = requests.get(url, params=params, timeout=5)
        return {'status': response.status_code, 'text': response.text}
    except Exception as e:
        return {'status': -1, 'error': str(e)}

async def send_huahua_danmu(text: str, userid: str = None, dmid: str = None):
    params = {'text': text}
    if userid:
        params['userid'] = userid
    if dmid:
        params['dmid'] = dmid
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(url, params=params, timeout=5) as resp:
                resp_text = await resp.text()
                return {'status': resp.status, 'text': resp_text}
    except Exception as e:
        return {'status': -1, 'error': str(e)}
